﻿using System;
using System.Collections.Generic;
using System.Drawing.Drawing2D;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace OurMemory
{
    internal class CustomMonthCalendar : MonthCalendar
    {
        private Dictionary<DateTime, bool> heartMarks = new Dictionary<DateTime, bool>();

        public void AddHeartMark(DateTime date)
        {
            if (!heartMarks.ContainsKey(date))
            {
                heartMarks[date] = true;
                this.Invalidate(); // 触发重绘
            }
        }

        protected override void OnDateSelected(DateRangeEventArgs e)
        {
            base.OnDateSelected(e);
            AddHeartMark(e.Start);
        }

        protected override void OnPaint(PaintEventArgs e)
        {
            base.OnPaint(e);

            foreach (var kvp in heartMarks)
            {
                if (kvp.Value)
                {
                    DrawHalfHeart(e.Graphics, kvp.Key);
                }
            }
        }

        private void DrawHalfHeart(Graphics g, DateTime date)
        {
            Rectangle rect = GetDayRectangle(date);
            if (rect.IsEmpty) return;

            using (GraphicsPath path = CreateHalfHeartPath(rect))
            {
                using (Brush brush = new SolidBrush(Color.Red)) // 爱心颜色
                {
                    g.FillPath(brush, path);
                }
            }
        }

        private GraphicsPath CreateHalfHeartPath(Rectangle rect)
        {
            int width = rect.Width / 2; // 半个爱心占用一半宽度
            int height = rect.Height;
            int left = rect.Left + rect.Width / 4; // 调整位置使爱心居中
            int top = rect.Top;

            GraphicsPath path = new GraphicsPath();
            path.AddEllipse(left, top, width, height); // 左侧圆弧
            path.AddLine(left + width, top, left + width, top + height); // 直线部分

            return path;
        }

        private Rectangle GetDayRectangle(DateTime date)
        {
            // 这是一个简化的方法，实际应用中可能需要更复杂的逻辑来获取日期对应的矩形区域
            // 此处假设每个日期占据相同的矩形区域，具体实现依赖于 MonthCalendar 的内部布局
            // 对于精确的位置，可以考虑遍历所有可见日期并计算位置
            return new Rectangle(0, 0, 0, 0); // 返回空矩形表示未找到对应位置
        }
    }
}
